import utils from '../../../../utils';
import EditFormUtils from './utils';
const { getContextComponents } = utils;

export default [
  {
    type: 'datagrid',
    input: true,
    label: '显示条件',
    key: 'customConditionalInput',
    tooltip: 'customConditionalInputs',
    weight: 20,
    components: [
      {
        type: 'select',
        input: true,
        label: 'who',
        key: 'who',
        dataSrc: 'custom',
        valueProperty: 'value',
        data: {
          custom(context) {
            const components = getContextComponents(context);
            return components;
          },
        },
      },
      {
        type: 'select',
        input: true,
        label: 'when',
        key: 'when',
        dataSrc: 'custom',
        valueProperty: 'value',
        data: {
          custom() {
            return [
              { label: '≠', value: 1 }, // 不能从 0 开始，因为判断 0 会为空
              { label: '=', value: 2 },
              { label: '>', value: 3 },
              { label: '<', value: 4 },
              { label: 'include', value: 5 },
              { label: 'not include', value: 6 },
              { label: 'in', value: 7 },
              { label: 'not in', value: 8 },
            ];
          },
        },
      },
      {
        label: 'eq',
        key: 'eq',
        input: true,
        type: 'textfield',
      },
    ],
  },
  EditFormUtils.javaScriptValue(
    'Advanced Conditions',
    'customConditional',
    'conditional.json',
    110,
    '<p>You must assign the <strong>show</strong> variable a boolean result.</p>' +
      '<p><strong>Note: Advanced Conditional logic will override the results of the Simple Conditional logic.</strong></p>' +
      '<h5>Example</h5><pre>show = !!data.showMe;</pre>',
    '<p><a href="http://formio.github.io/formio.js/app/examples/conditions.html" target="_blank">Click here for an example</a></p>',
  ),
];
